import gtk, pygtk
pygtk.require('2.0')
import Board, DrawingController, Spec

class Screen(gtk.Window):
	
	def __init__(self):
		gtk.Window.__init__(self)
		self.connect("delete_event", gtk.main_quit)	# what to do when closed
		self.set_title("Pellegrino's first bimester screen")
		
		background = gtk.VBox() #contentPane
		self.add(background)

		self.box_options = gtk.HBox() # we'll place the options to paint here
		self.canvas_box = Board.Board()  # place to draw		
		background.pack_start(self.box_options)
		background.pack_start(gtk.HSeparator())
		background.pack_start(self.canvas_box)
		
		self.__put_options(self.box_options)
		self.drawing_controller = DrawingController.DrawingController(self.canvas_box)
	
	
	def __put_options(self, box):
		"""Put the option on top of the screen"""
		self.__put_drawing_actions(box)
		box.pack_start(gtk.VSeparator(), False)
		self.__put_shapes(box)
		box.pack_start(gtk.VSeparator(), False)
		self.__put_trace(box)
		box.pack_start(gtk.VSeparator(), False)
		self.__put_colors(box)
		box.pack_start(gtk.VSeparator(), False)
		self.__put_grouping(box)

	
	def __put_drawing_actions(self, box):
		""" Putting draw and clear all"""
		boxV = gtk.VBox()
		box.pack_start(boxV)
		self.draw_button = gtk.Button("Draw")
		self.clear_button = gtk.Button("Clear All")
		self.draw_button.connect("clicked", self.__clicked_draw)
		self.clear_button.connect("clicked", self.__clicked_clearall)
		boxV.pack_start(self.draw_button)
		boxV.pack_start(self.clear_button)		

		
	def __put_shapes(self, box):
		""" Putting Shapes """
		boxV = gtk.VBox()
		box.pack_start(boxV)
		self.radio_line = gtk.RadioButton(None, "Line")
		self.radio_circle = gtk.RadioButton(self.radio_line, "Circle")
		self.radio_polygon = gtk.RadioButton(self.radio_line, "Polygon")
		boxV.pack_start(gtk.Label("Shapes"))
		boxV.pack_start(self.radio_line)
		boxV.pack_start(self.radio_circle)
		boxV.pack_start(self.radio_polygon)

		
	def __put_trace(self, box):		
		""" Putting Trace """
		boxV = gtk.VBox()
		box.pack_start(boxV)
		self.radio_normal = gtk.RadioButton(None, "Normal")
		self.radio_dotted = gtk.RadioButton(self.radio_normal, "Dotted")
		self.radio_dashed = gtk.RadioButton(self.radio_dotted, "Dashed")
		boxV.pack_start(gtk.Label("Trace"))
		boxV.pack_start(self.radio_normal)
		boxV.pack_start(self.radio_dotted)
		boxV.pack_start(self.radio_dashed)

		
	def __put_colors(self, box):	
		""" Putting colors """
		boxV = gtk.VBox()
		box.pack_start(boxV)
		self.check_double = gtk.CheckButton("Double")
		self.check_red = gtk.CheckButton("Red")
		self.check_green = gtk.CheckButton("Green")
		self.check_blue = gtk.CheckButton("Blue")
		boxV.pack_start(gtk.Label("Colors"))
		boxV.pack_start(self.check_double)
		boxV.pack_start(self.check_red)
		boxV.pack_start(self.check_green)
		boxV.pack_start(self.check_blue)

		
	def __put_grouping(self, box):
		""" Putting Grouping """
		boxV = gtk.VBox()
		box.pack_start(boxV)
		self.check_select = gtk.CheckButton("Select Multiple")
		self.button_group = gtk.Button("Group")
		self.button_group.connect("clicked", self.__clicked_group)
		self.button_ungroup = gtk.Button("Ungroup")
		self.button_ungroup.connect("clicked", self.__clicked_ungroup)
		boxV.pack_start(gtk.Label("Grouping"))
		boxV.pack_start(self.check_select)
		boxV.pack_start(self.button_group)
		boxV.pack_start(self.button_ungroup)
		
	
	def __clicked_draw(self, draw_button):
		""" Draw the function according specifitions """
		self.get_spec()
		self.spec.points = self.canvas_box.points
		self.canvas_box.points = []
		print("Draw!") # debug only
		self.drawing_controller.draw(self.spec)
			
	def __clicked_clearall(self, clear_button):
		""" Clear all function """
		print("Clear All!!!!") # debug only
		self.drawing_controller.clear_all()

	
	
	def __clicked_group(self, group_button):
		""" Group shapes function """
		print("Group!!!") # debug only
	
	
	def __clicked_ungroup(self, ungroup_button):
		""" Ungroup shapes function """
		print("Ungroup...") # debug only
	
	
	def get_spec(self):
		""" Set up self.spec using the information on buttons """
		self.spec = Spec.Spec()
		# Shapes
		self.spec.shape = [b for b in self.radio_line.get_group() if b.get_active()][0].get_label()
		# Trace
		self.spec.trace = [b for b in self.radio_normal.get_group() if b.get_active()][0].get_label()
		# Color
		self.spec.double = self.check_double.get_active()
		self.spec.color = [self.check_red.get_active(), self.check_green.get_active(), self.check_blue.get_active()]
		# Grouping
		self.spec.grouping = self.check_select.get_active()
			
			
if __name__ == "__main__":
	win = Screen()
	win.show_all()
	gtk.main()
